using System;
using System.ComponentModel;
using AntEater.ComponentModel.Building;

namespace AntEater.ComponentModel
{
    /// <summary>
    /// Represents the options.
    /// </summary>
    [Serializable]
    public class Options : INotifyPropertyChanged
    {
        /// <summary>
        /// Occurs when the instance or some of his child objects has changed.
        /// </summary>
        public event EventHandler<EventArgs> Changed;

        /// <summary>
        /// Occurs when a property of the instance has changed
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Initializes a new instance of the <see cref="Options"/> class.
        /// </summary>
        public Options() {
            this._externalBuildProperties = new ExternalBuildPropertyCollection();
            this._externalBuildProperties.Changed += new EventHandler<EventArgs>(ExternalBuildPropertiesChanged);

            this._buildFileExtensions = new BuildFileExtensionCollection();
            this._buildFileExtensions.Changed += new EventHandler<EventArgs>(BuildFileExtensionsChanged);

            this._buildLoggingVerbosity = BuildingLoggerVerbosity.Minimal;
        }

        private string _buildEnginePath;

        /// <summary>
        /// Gets or sets the build engine path.
        /// </summary>
        /// <value>The build engine path.</value>
        public string BuildEnginePath {
            get { return _buildEnginePath; }
            set {
                if (_buildEnginePath != value) {
                    _buildEnginePath = value;
                    this.OnPropertyChanged("BuildEnginePath");
                }
            }
        }

        private BuildingLoggerVerbosity _buildLoggingVerbosity;

        /// <summary>
        /// Gets or sets the build logging verbosity.
        /// </summary>
        /// <value>The build logging verbosity.</value>
        public BuildingLoggerVerbosity BuildLoggingVerbosity {
            get { return _buildLoggingVerbosity; }
            set {
                if (_buildLoggingVerbosity != value) {
                    _buildLoggingVerbosity = value;
                    this.OnPropertyChanged("BuildLoggingVerbosity");
                }
            }
        }

        private bool _showImportedTargets;

        /// <summary>
        /// Gets or sets the show imported targets.
        /// </summary>
        /// <value>The show imported targets.</value>
        public bool ShowImportedTargets {
            get { return _showImportedTargets; }
            set {
                if (_showImportedTargets != value) {
                    _showImportedTargets = value;
                    this.OnPropertyChanged("ShowImportedTargets");
                }
            }
        }

        private BuildFileExtensionCollection _buildFileExtensions;

        /// <summary>
        /// Gets the build file extensions.
        /// </summary>
        /// <value>The build file extensions.</value>
        public BuildFileExtensionCollection BuildFileExtensions {
            get { return _buildFileExtensions; }
        }

        private ExternalBuildPropertyCollection _externalBuildProperties;

        /// <summary>
        /// Gets the external build properties.
        /// </summary>
        /// <value>The external build properties.</value>
        public ExternalBuildPropertyCollection ExternalBuildProperties {
            get { return _externalBuildProperties; }
        }

        /// <summary>
        /// Externals the build properties changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void ExternalBuildPropertiesChanged(object sender, EventArgs e) {
            this.OnChanged();
        }

        /// <summary>
        /// Builds the file extensions changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void BuildFileExtensionsChanged(object sender, EventArgs e) {
            this.OnChanged();
        }

        /// <summary>
        /// Called when [changed].
        /// </summary>
        protected void OnChanged() {
            if (this.Changed != null) {
                this.Changed(this, new EventArgs());
            }
        }

        /// <summary>
        /// Called when [property changed].
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        protected void OnPropertyChanged(string propertyName) {
            if (this.PropertyChanged != null) {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }

            this.OnChanged();
        }
    }
}
